package com.wn.servlet.req;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author yellow Docter
 * @date 2022 -06-29
 * @desc
 *
 *  获得URL的信息
 *  http://localhost:8080/day03/demo02
 *  http:       协议
 *  localhost   ip地址
 *  8080        端口
 *  day03       项目的访问路径
 *  demo02      资源路径
 */
@WebServlet("/demo02")
public class Demo02Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // URL 包含 uri
        // URL 协议:ip地址:端口:项目的访问路径/资源
        System.out.println(req.getRequestURI());//获得URI        /day03/demo02

        System.out.println(req.getRequestURL());//获得URL        http://localhost:8080/day03/demo02

        // :0:0:0:0:0:0:1是ipv6的表现形式，对应ipv4来说相当于127.0.0.1，也就是本机
        System.out.println(req.getRemoteAddr());//获得远程IP地址     0:0:0:0:0:0:0:1
        System.out.println(req.getServerPort()); // 服务器端口
        System.out.println(req.getContextPath());//项目部署的名称

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

